package com.example.demo.design.observe_pattern.two;

import java.util.ArrayList;

/**
 * @Author: liull
 * @Description: 战队控制中心
 * @Date: Created in 9:35 2021/4/2
 * @Modified By:
 */
public abstract class AllyControllerCenter {
    /**
     * 战队名
     */
    protected String allyName;

    /**
     * 战队成员 四名玩家
     */
    protected ArrayList<Observer> players = new ArrayList<>();

    public String getAllyName() {
        return allyName;
    }

    public void setAllyName(String allyName) {
        this.allyName = allyName;
    }

    public void quit(Observer o) {
        System.out.println(o.getName() + "退出" + this.allyName + "战队");
        players.remove(o);
    }

    public void join(Observer o) {
        System.out.println(o.getName() + "加入" + this.allyName + "战队");
        players.add(o);
    }

    public AllyControllerCenter(String allyName) {
        this.allyName = allyName;
    }

    /**
     * 当某名玩家遭受攻击时通知其他队友前来支援
     * 
     * @param name
     */
    public abstract void notifyObserver(String name);
}
